% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% Table C
clear;
tic
cd ..\..\Simulations_VC\Counterfactual_sim\MS_produits_CalvoPlus

load  ..\..\Estimation_param\MS_produits_CPlus\actual_moments_k
weight=actual_moments_k(:,12);
sum(weight)
secteur=actual_moments_k(:,1);

load  ..\..\Simulations_VC\MS_produits_CPlus\stat_d
param=stat_d;

data=param(:,5:9)

load  ..\..\Simulations_VC\Counterfactual_sim\MS_produits_CalvoPlus\stat_simu_out.mat

for jj=1:3
    
    data_sim=stat_simu_out(jj).stat_simu_out(:,5:9);
    
    
for i=1:5
y=[data_sim(:,i) data(:,i)];
y=[data(:,i) data_sim(:,i)];

% r1 = corrcoef(y) 
% corr(i)=r1(2,1)% Traditional Correlation Matrix 
% r2 = weightedcorrs(y, weight) % Weighted Correlation Matrix
% corrw(i)=r2(2,1)% Traditional Correlation Matrix 

%p(i,:) = polyfit(y(:,1),y(:,2),1)
lm = fitlm(y(:,1),y(:,2))
p(i,:)=lm.Coefficients(2,1)
v(i,:)=lm.Coefficients(2,4)
y_he=[data((secteur ~=5),i) data_sim((secteur ~=5),i)];

mat_R2(i,:)= lm.Rsquared.Adjusted

% r1 = corrcoef(y_he) 
% corrhe(i)=r1(2,1)% Traditional Correlation Matrix 
% 
% r2 = weightedcorrs(y_he, weight((secteur ~=5))) % Weighted Correlation Matrix
% corrw_he(i)=r2(2,1)% Traditional Correlation Matrix 
%phe(i,:) = polyfit(y_he(:,1),y_he(:,2),1)
lm = fitlm(y_he(:,1),y_he(:,2))
phe(i,:)=lm.Coefficients(2,1)
vhe(i,:)=lm.Coefficients(2,4)

mat_R2_he(i,:)= lm.Rsquared.Adjusted

end
%corrt(jj,:)=corr;
%corrthe(jj,:)=corrhe;

%corrtw(jj,:)=corrw;
%corrthew(jj,:)=corrw_he;

p_tot(:,jj)=p(:,1)
phe_tot(:,jj)=phe(:,1)

v_tot(:,jj)=v(:,1)
vhe_tot(:,jj)=vhe(:,1)

mat_R2_tothe(:,jj)= mat_R2_he
mat_R2_tot(:,jj)= mat_R2

end
% corrtw
% corrthew
% 
% 
% corrt
% 
% corrthe